package snsdbook.engine.message;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import snsdbook.engine.FileManager;
import util.Util;

public class UpdateOrderMessage implements MessageInterface {

  private static final long serialVersionUID = -1501922804932831309L;
  private String filename_;
  private long timestamp_;
  private byte[] data_;
  
  public UpdateOrderMessage(String filename, byte[] data, long timestamp) {
    filename_ = filename;
    data_ = data;
    timestamp_ = timestamp;
  }
  
  @Override
  public String ProcessAsServer(ObjectInputStream is, ObjectOutputStream os) {
    Util.Send(os, this);
    return "";
  }

  @Override
  public String ProcessAsClient(ObjectInputStream is, ObjectOutputStream os,
      FileManager manager) {
    manager.WriteToFile(filename_, data_, timestamp_);
    return "";
  }
  
  public String toString() {
    return "UPDATE ORDER, FILE=" + filename_;
  }

}
